<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'test.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
body, html, #allmap {
	width: 100%;
	height: 100%;
	overflow: hidden;
	margin: 0;
	font-family: "微软雅黑";
}

#l-map {
	height: 100%;
	width: 78%;
	float: left;
	border-right: 2px solid #bcbcbc;
}

#r-result {
	height: 100%;
	width: 20%;
	float: left;
}
</style>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=gkhZkvMMhPRMs1ybtbM7nmhH1ryHr6Dp"></script>
<script type="text/javascript"
	src="http://api.map.baidu.com/library/AreaRestriction/1.2/src/AreaRestriction_min.js"></script>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript">
	function getData() {
		$.ajax({
			type : 'GET',
			url : 'testCtrl/testData.ins',
			dataType : "json",
			success : function(data) {
				//var content = new Array();
				for (var i = 0; i < data.length; i++) {
					var marker = new BMap.Marker(new BMap.Point(data[i].lng, data[i].lat));
					var content = "";
					for (var j = 0; j < data[i].info.length; j++) {
						content += "code : " + data[i].info[j].code + "<br/>name:" + data[i].info[j].name + "<br/>";
					}
					map.addOverlay(marker);
					(function(i) {
						var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
						marker.addEventListener("click", function() {
// 							this.openInfoWindow(infoWindow);
							alert("hello world");
						})
						marker.addEventListener("mouseover",function(){ 
							this.openInfoWindow(infoWindow);
						})
// 						marker.addEventListener("mouseout",function(){ 
// 							this.closeInfoWindow(infoWindow);
// 							this.openInfoWindow(infoWindow);
// 						})
					})(i);
				}
			},
			error : function(data) {
				alert("请检查网络连接");
			}
		})
	}
</script>
</head>

<body>
	<div id="allmap"></div>
</body>
<script type="text/javascript">
	// 百度地图API功能
	var map = new BMap.Map("allmap");
// 	map.centerAndZoom("黑龙江", 7);
	map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
	map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用

	map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
	map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件

	// 	var b = new BMap.Bounds(new BMap.Point(120.14122, 43.700658), new BMap.Point(135.300592, 53.951718));
	// 	try {
	// 		BMapLib.AreaRestriction.setBounds(map, b);
	// 	} catch (e) {
	// 		alert(e);
	// 	}

	function getBoundary() {
		var bdary = new BMap.Boundary();
		bdary.get("黑龙江省", function(rs) { //获取行政区域
			//map.clearOverlays(); //清除地图覆盖物       
			var count = rs.boundaries.length; //行政区域的点有多少个
			if (count === 0) {
				alert('未能获取当前输入行政区域');
				return;
			}
			var pointArray = [];
			for (var i = 0; i < count; i++) {
				var ply = new BMap.Polygon(rs.boundaries[i], {
					strokeWeight : 2,
					strokeColor : "#ff0000"
				}); //建立多边形覆盖物
				map.addOverlay(ply); //添加覆盖物
				pointArray = pointArray.concat(ply.getPath());
			}
			map.setViewport(pointArray); //调整视野  
			addlabel();
		});
	}
	getBoundary();
// 	setTimeout(function() {
// 		getBoundary();
// 	}, 2000);

	// 编写自定义函数,创建标注
	function addMarker(point) {
		var marker = new BMap.Marker(point);
		map.addOverlay(marker);
	}
	// 随机向地图添加25个标注
	getData();
</script>
</html>
